<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/plugin/jquery-2.1.4.min.js"></script>
	<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
	<script type="text/javascript" src="${path }/resource/js/systools/MJsBase.js"></script>
<!-- 将百度地图API引入，设置好自己的key -->  
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=xFaAvGxMbX9ToptGnBbOGdjOWPZPG5h7"></script>  
</head>
<body>  

<div class="main-div">  
<form class="form-horizontal" id="dataform" onsubmit="javascripr:return false;">
<div class="form-group" style="margin-top:20px;">
		<label class="col-sm-2 control-label">经纬度<span class="text-danger">*</span></label>
			<div class="col-sm-2" >
				<input type="text" class="form-control" 
					value="" name="siteLongitude" id="lng" readonly="readonly">
			</div>
			<div class="col-sm-2" >
				<input type="text" class="form-control"
					value="" name="siteLatitude" id="lat" readonly="readonly">
			</div>
</div>
		<div class="form-group ">
			
			<label class="col-sm-2 control-label">地址<span class="text-danger">*</span></label>
			<div class="col-sm-4" >
				<input type="text"  name='sever_add' id='sever_add' class="form-control" readonly="readonly">
			</div>
				<a href="javascript:;" onclick="addLngLat()"
					class="btn btn-success radius"><i class="fa fa-check"></i> 确定</a>&nbsp;&nbsp;&nbsp;&nbsp; <a
					 class="btn btn-danger radius" href="javascript:;" onclick="MTools.closeForm()" ><i class="fa fa-close"></i>取消</a>
			
		</div>
</form>
    <div id='allmap' style='width: 80%; height: 65%; position: absolute; '></div>  
</div>  
</body>  
</html>  

<script type="text/javascript">
function addLngLat(){
	parent.addLngLat($("#lng").val(),$("#lat").val());
	MTools.closeForm();
}
    function validate() {  
        var sever_add = document.getElementsByName('sever_add')[0].value;  
        if (isNull(sever_add)) {  
            alert('请选择地址');  
            return false;  
        }  
        return true;  
    }  
  
    //判断是否是空  
    function isNull(a) {  
        return (a == '' || typeof(a) == 'undefined' || a == null) ? true : false;  
    }  
 
    var map = new BMap.Map("allmap");  
    var geoc = new BMap.Geocoder();   //地址解析对象  
    var markersArray = [];  
    //var geolocation = new BMap.Geolocation();  
  //113.138706,27.832715
    var point = new BMap.Point(112.952002,28.185059);  
    map.centerAndZoom(point, 13); // 中心点  
 
    map.addEventListener("click", showInfo);  
    map.enableScrollWheelZoom();    //启用滚轮放大缩小，默认禁用
    map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用
    map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
    map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件 
    //清除标识  
    function clearOverlays() {  
        if (markersArray) {  
            for (i in markersArray) {  
                map.removeOverlay(markersArray[i])  
            }  
        }  
    }  
    //地图上标注  
    function addMarker(point) {  
        var marker = new BMap.Marker(point);  
        markersArray.push(marker);  
        clearOverlays();  
        map.addOverlay(marker);  
    }  
    //点击地图时间处理  
    function showInfo(e) {  
        document.getElementById('lng').value = e.point.lng;  
        document.getElementById('lat').value =  e.point.lat;  
        geoc.getLocation(e.point, function (rs) {  
            var addComp = rs.addressComponents;  
            var address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;  
                document.getElementById('sever_add').value = address;  
        });  
        addMarker(e.point);  
    }  
</script>  
</body>
</html>
